//
//  WelcomeViewController.m
//  TigerClef
//
//  Created by Alison Y. Chang on 6/28/13.
//  Copyright (c) 2013 Christopher Laguna. All rights reserved.
//

#import "WelcomeViewController.h"
#import "AppDelegate.h"
#import "LevelSelectViewController.h"

@interface WelcomeViewController ()

@end

@implementation WelcomeViewController
@synthesize page;
@synthesize welcomeText;
@synthesize welcomeTextArray;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    welcomeTextArray = [NSMutableArray arrayWithObjects:
                        @"\nWelcome to TigerClefs! \n\nIn this game, you will learn to identify notes on a musical staff.",
                        @"Let's start with Level 1: the treble clef. ",
                        @"As you beat each level, you will unlock the next, with a new clef!",
                        @"",
                        nil];
    
    
    UIView *topView = [[UIView alloc] initWithFrame: CGRectMake(0,0, self.view.frame.size.width, self.view.frame.size.height)];
    topView.backgroundColor = [[UIColor alloc] initWithRed:0.6 green:0.7 blue:0.9 alpha:1.0];
    [self.view addSubview:topView];
    
    
    page = 0;
    welcomeText = [[UITextView alloc] initWithFrame:CGRectMake(5, 5, self.view.frame.size.width - 10, self.view.frame.size.height - 100)];
    welcomeText.text = [self displayText:page];
    welcomeText.font = [UIFont fontWithName:@"Times New Roman" size:20];
    welcomeText.editable = NO;
    [self.view addSubview:welcomeText];
    

    
    UIImageView *myImageView = [[UIImageView alloc] initWithImage: [UIImage imageNamed:@"tiger.png"]];
    
    myImageView.frame = CGRectMake(0, 150, 300, 400);
    [self.view addSubview:myImageView];
    
    
    
        
    UIButton *nextButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    nextButton.frame = CGRectMake((self.view.frame.size.width/2) - 30, self.view.frame.size.height - 80, 60, 30);
    [nextButton setTitle:@"Next" forState:(UIControlState)UIControlStateNormal];
    [nextButton addTarget:self action:@selector(nextClicked:) forControlEvents:(UIControlEvents)UIControlEventTouchUpInside];
    [self.view addSubview:nextButton];
    
 
    
}

- (void)nextClicked : (id) sender{
    page++;
    welcomeText.text = [self displayText:page];
}

- (NSString*)displayText: (int) pageNum
{
    //NSLog([NSString stringWithFormat: @"%d", welcomeTextArray.count]);
    if(pageNum >= welcomeTextArray.count){
        AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
        [appDelegate.navController pushViewController: [[LevelSelectViewController alloc] init] animated:YES];
        return @"";
        
    }
    else{

        if([(NSString*) [welcomeTextArray objectAtIndex: pageNum] isEqualToString: @""]){
            UIImageView *myImageView = [[UIImageView alloc] initWithImage: [UIImage imageNamed:@"yay.gif"]];
            
            myImageView.frame = CGRectMake(150, 100, 120, 120);
            [self.view addSubview:myImageView];
        }
        return (NSString*) [welcomeTextArray objectAtIndex: pageNum];
    }
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}





@end
